from flask import Flask, render_template, request, redirect, url_for
import mysql.connector
import random
from datetime import datetime

# -*- coding: utf-8 -*-

app = Flask(__name__)


def connect_to_database():
    global mydb
    try:
        mydb = mysql.connector.connect(
            host="localhost",
            user="root",
            password="123456",
            database="my"
        )
        return mydb
    except mysql.connector.Error as error:
        print("数据库连接错误：", error)
        return None


@app.route('/')
def main():
    return redirect(url_for('index'))


@app.route('/index', methods=['GET', 'POST'])
def index():
    return render_template('index.html')


@app.route('/index2', methods=['GET', 'POST'])
def index2():
    if request.method == 'POST':
        admin = request.form['admin']
        print(admin)
        return redirect(url_for('index5'))
    return render_template('index-2.html')


@app.route('/index3', methods=['GET', 'POST'])
def index3():
    if request.method == 'POST':
        admin = request.form['admin']
        print(admin)
        return redirect(url_for('index5'))
    return render_template('index-3.html')


@app.route('/index4', methods=['GET', 'POST'])
def index4():
    if request.method == 'POST':
        admin = request.form['admin']
        print(admin)
        return redirect(url_for('index5'))
    return render_template('index-4.html')


@app.route('/index5', methods=['GET', 'POST'])
def index5():
    if request.method == 'POST':
        admin = request.form['admin']
        print(admin)
        return redirect(url_for('index5'))
    return render_template('index-5.html')


if __name__ == '__main__':
    app.run(debug=True)